package com.deyang.mycommon.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;

import com.deyang.mycommon.R;
import com.deyang.mycommon.minterface.IDialogSelectOptionListener;
import com.flyco.animation.BounceEnter.BounceTopEnter;
import com.flyco.animation.SlideExit.SlideBottomExit;
import com.flyco.dialog.entity.DialogMenuItem;
import com.flyco.dialog.listener.OnOperItemClickL;
import com.flyco.dialog.widget.NormalListDialog;

import java.util.ArrayList;

public class DialogUtil {


    /**
     * 选择对话框
     *
     * @param activity
     * @param options
     * @param iDialogSelectOptionListener
     */
    public static void showSelectOptionDialog(Activity activity, String title, String[] options, final IDialogSelectOptionListener iDialogSelectOptionListener) {
        BounceTopEnter mBasIn = new BounceTopEnter();
        SlideBottomExit mBasOut = new SlideBottomExit();
        final ArrayList<DialogMenuItem> mMenuItems = new ArrayList<>();
        for (String option : options) {
            mMenuItems.add(new DialogMenuItem(option, R.drawable.select_options));
        }
        final NormalListDialog dialog = new NormalListDialog(activity, mMenuItems);
        dialog.isTitleShow(TextUtils.isEmpty(title) ? false : true)
                .title(TextUtils.isEmpty(title) ? "请选择" : title)
                .showAnim(mBasIn)//
                .titleBgColor(activity.getResources().getColor(R.color.select_dialog_title_bg))//
                .dismissAnim(mBasOut)//
                .show();
        dialog.setOnOperItemClickL(new OnOperItemClickL() {
            @Override
            public void onOperItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                dialog.dismiss();
                iDialogSelectOptionListener.onOperItemClick(i);
            }
        });
    }

    /**
     * 获取正在加载。。。 对话框
     *
     * @param context
     * @return
     */
    public static Dialog getLoadingDialog(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.loading, null);
        Dialog dialog = new Dialog(context, R.style.dialog);
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(false);
        return dialog;
    }

}
